﻿<UserControl x:Class="LearningGames.Framework.Quiz.TextProblemPresenter"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:my="clr-namespace:LearningGames.Framework"
            xmlns:interaction="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Storyboard x:Key="wrongAnswerAnimation" my:StoryboardManager.ID="wrongAnswerAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="labelWrong" Storyboard.TargetProperty="Opacity">
                <LinearDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                <LinearDoubleKeyFrame KeyTime="00:00:0.25" Value="1" />
                <LinearDoubleKeyFrame KeyTime="00:00:0.75" Value="1" />
                <LinearDoubleKeyFrame KeyTime="00:00:1" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="rightAnswerAnimation" my:StoryboardManager.ID="rightAnswerAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="labelRight" Storyboard.TargetProperty="Opacity">
                <LinearDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                <LinearDoubleKeyFrame KeyTime="00:00:0.25" Value="1" />
                <LinearDoubleKeyFrame KeyTime="00:00:0.75" Value="1" />
                <LinearDoubleKeyFrame KeyTime="00:00:1" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <Grid Background="Azure">
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="220*" />
            <ColumnDefinition Width="80*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border Grid.ColumnSpan="2" Margin="5" BorderBrush="Blue" BorderThickness="2" CornerRadius="4">
            <ContentPresenter Content="{Binding Problem}" ContentTemplate="{Binding DataTemplate}" />
        </Border>
        <!-- GRRR - Can't use updateSourceTrigger=PropertyChanged in SL. Was Text="{Binding Answer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" -->
        <TextBox Grid.Row="1" 
                 x:Name="textBoxAnswer"
                 Text="{Binding Answer, Mode=TwoWay}" 
                 IsEnabled="{Binding AllowAnswer}"
                 my:FocusHelpers.FocusEvent="{Binding SetTextboxFocus}"
                 my:EnterKeyHelpers.EnterKeyCommand="{Binding SubmitAnswerCommand}"
                 Margin="10" 
                 FontFamily="Segoe UI" 
                 FontSize="40" 
                 FontWeight="Bold" 
                 BorderBrush="Blue" 
                 MaxLength="5" >
        </TextBox>
        <Button x:Name="okButton" Content="OK" Grid.Column="1" Grid.Row="1" Margin="10" FontSize="20" Command="{Binding SubmitAnswerCommand}" />
        <TextBlock FontSize="40" FontWeight="Bold" Foreground="Red" Margin="10" 
               Name="labelWrong" Opacity="0" VerticalAlignment="Bottom">oops! try again</TextBlock>
        <TextBlock FontSize="40" FontWeight="Bold" Foreground="Green" Margin="10" 
               Name="labelRight" Opacity="0" VerticalAlignment="Bottom">well done!</TextBlock>
        <!--
        <UserControl
            my:StoryboardHelpers.StoryboardName="rightAnswerAnimation"
            my:StoryboardHelpers.Completed="{Binding CompletedCommand}"
            my:StoryboardHelpers.BeginEvent="{Binding StartCorrectAnswer}" />
        <UserControl
            my:StoryboardHelpers.StoryboardName="wrongAnswerAnimation"
            my:StoryboardHelpers.Completed="{Binding CompletedCommand}"
            my:StoryboardHelpers.BeginEvent="{Binding StartWrongAnswer}" /> -->
    </Grid>
</UserControl>
